// 更改3Dtile模型位置大小旋转（初始化用）
function change3Dtiles(model, lon, lat, height, roll, scale, resolve) {
    model.readyPromise.then(function (argument) {
        var position = Cesium.Cartesian3.fromDegrees(lon, lat, height);
        var mat = Cesium.Transforms.eastNorthUpToFixedFrame(position);
        var rotationZ = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(
            roll)));
        Cesium.Matrix4.multiply(mat, rotationZ, mat);
        if (scale != undefined) {
            var modelScale = Cesium.Matrix4.fromUniformScale(scale);
            Cesium.Matrix4.multiply(mat, modelScale, mat);
        }
        model._root.transform = mat;
        if (resolve != undefined) {
            if (model.asset.extras[0] != undefined) {// 初始化获取建筑信息用
                var extras = model.asset.extras;
                return resolve(extras)
            }
            else {// 摄像机/雷达用
                return resolve(position)
            }
        }
    })
};

// 旋转3Dtiles
function changeRotation(model, position, roll) {
    model.readyPromise.then(function (argument) {
        var mat = Cesium.Transforms.eastNorthUpToFixedFrame(position);
        var rotationZ = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(
            roll)));
        Cesium.Matrix4.multiply(mat, rotationZ, mat);
        var modelScale = Cesium.Matrix4.fromUniformScale(model.asset.extras[0].scale);
        Cesium.Matrix4.multiply(mat, modelScale, mat);
        model._root.transform = mat;
    })
}

// 旋转Gltf
function changeGltf(model, rtaleX) {
    let m = model.modelMatrix;
    let rotationM = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rtaleX));// 角度转化为3维矩阵
    let newMatrix4 = Cesium.Matrix4.multiplyByMatrix3(m, rotationM, new Cesium.Matrix4());
    model.modelMatrix = newMatrix4
}

export { change3Dtiles, changeGltf, changeRotation }